Double field


In [1]:
from konfoo import Index, Byteorder, Double

Item

Item type of the field class.


In [2]:
Double.item_type


Out[2]:
ItemClass.Double = 31

Checks if the field class is a bit field.


In [3]:
Double.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
Double.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
Double.is_decimal()


Out[5]:
False

Checks if the field class is a floating point number field.


In [6]:
Double.is_float()


Out[6]:
True

Checks if the field class is a pointer field.


In [7]:
Double.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
Double.is_stream()


Out[8]:
False

Checks if the field class is a string field.


In [9]:
Double.is_string()


Out[9]:
False

Field


In [10]:
double = Double(byte_order='auto')

In [11]:
double = Double()

Field view


In [12]:
double


Out[12]:
Double(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=8, bit_offset=0), bit_size=64, value=0.0)

In [13]:
str(double)


Out[13]:
'Double64(Index(byte=0, bit=0, address=0, base_address=0, update=False), Alignment(byte_size=8, bit_offset=0), 64, 0.0)'

In [14]:
repr(double)


Out[14]:
'Double(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=8, bit_offset=0), bit_size=64, value=0.0)'

Field name


In [15]:
double.name


Out[15]:
'Double64'

Field index


In [16]:
double.index


Out[16]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Byte index of the field within the byte stream.


In [17]:
double.index.byte


Out[17]:
0

Bit offset relative to the byte index of the field within the byte stream.


In [18]:
double.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
double.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
double.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


In [21]:
double.index_field(index=Index())


Out[21]:
Index(byte=8, bit=0, address=8, base_address=0, update=False)

Field alignment


In [22]:
double.alignment


Out[22]:
Alignment(byte_size=8, bit_offset=0)

Byte size of the field group which the field is aligned to.


In [23]:
double.alignment.byte_size


Out[23]:
8

Bit offset of the field within its aligned field group.


In [24]:
double.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
double.bit_size


Out[25]:
64

Field byte order


In [26]:
double.byte_order


Out[26]:
Byteorder.auto = 'auto'

In [27]:
double.byte_order.value


Out[27]:
'auto'

In [28]:
double.byte_order.name


Out[28]:
'auto'

In [29]:
double.byte_order = 'auto'

In [30]:
double.byte_order = Byteorder.auto

Field value

Maximal float field value.


In [31]:
double.max()


Out[31]:
1.7976931348623157e+308

Minimal float field value.


In [32]:
double.min()


Out[32]:
-1.7976931348623157e+308

Smallest float field value.


In [33]:
double.smallest()


Out[33]:
2.2250738585072014e-308

Epsilon float field value.


In [34]:
double.epsilon()


Out[34]:
1.1102230246251565e-16

Returns the float field value as a single precision floating point number.


In [35]:
double.value


Out[35]:
0.0

Returns the float field value aligned to its field group as a number of bytes.


In [36]:
bytes(double)


Out[36]:
b'\x00\x00\x00\x00\x00\x00\x00\x00'

In [37]:
bytes(double).hex()


Out[37]:
'0000000000000000'

Returns the float field value as an integer number.


In [38]:
int(double)


Out[38]:
0

Returns the float field value as a single precision floating point number.


In [39]:
float(double)


Out[39]:
0.0

Returns the float field value as a boolean value.


In [40]:
bool(double)


Out[40]:
False

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [41]:
double.describe()


Out[41]:
OrderedDict([('address', 0),
             ('alignment', [8, 0]),
             ('class', 'Double64'),
             ('index', [0, 0]),
             ('max', 1.7976931348623157e+308),
             ('min', -1.7976931348623157e+308),
             ('name', 'Double64'),
             ('order', 'auto'),
             ('size', 64),
             ('type', 'Field'),
             ('value', 0.0)])

Deserialize


In [42]:
double.deserialize(bytes.fromhex('000000000000f03f'), byte_order='little')


Out[42]:
Index(byte=8, bit=0, address=8, base_address=0, update=False)

In [43]:
double.value


Out[43]:
1.0

In [44]:
bytes(double)


Out[44]:
b'\x00\x00\x00\x00\x00\x00\xf0?'

In [45]:
bytes(double).hex()


Out[45]:
'000000000000f03f'

In [46]:
int(double)


Out[46]:
1

In [47]:
float(double)


Out[47]:
1.0

In [48]:
bool(double)


Out[48]:
True

Serialize


In [49]:
buffer = bytearray()

In [50]:
double.value = 1

In [51]:
double.value = 1.0

In [52]:
double.value = 0x1

In [53]:
double.value = 0b1

In [54]:
double.value = 0o1

In [55]:
double.value = True

In [56]:
double.value = 1.0

In [57]:
double.serialize(buffer, byte_order='little')


Out[57]:
Index(byte=8, bit=0, address=8, base_address=0, update=False)

In [58]:
buffer.hex()


Out[58]:
'000000000000f03f'

In [59]:
bytes(double).hex()


Out[59]:
'000000000000f03f'

In [ ]: